<script lang="ts" setup>
import { injectState } from "../state";
import { whManagerBsTbEnterpriseGetListUsingPost } from "@/genapi/wh";
import { computedLoading } from "@/hooks/computed-loading";
import { DANGER_DESC_OPTIONS } from "@/config/enum-map";

defineOptions({ name: "Filters" });

const {
	filter,
	page: { isLoading },
} = injectState()!;

const initial = { ...toRaw(filter.value) };
const data = ref({ ...initial });

const search = () => {
	filter.value = { ...toRaw(data.value) };
};

const reset = () => {
	data.value = { ...initial };
};

const [state] = computedLoading(async () => {
	const { data } = await whManagerBsTbEnterpriseGetListUsingPost({ data: {} });
	return data?.map((item) => ({ label: item.name, value: item.id })) ?? [];
});
</script>

<template>
	<el-form class="filter-form" inline :model="data" :disabled="isLoading">
		<el-form-item label="企业名称">
			<el-select-v2
				v-model="data.enterpriseId"
				clearable
				:options="state ?? []"
				class="w-240px!"
				placeholder="请选择企业名称"
			/>
		</el-form-item>
		<el-form-item label="风险状态" prop="风险状态">
			<el-select-v2
				v-model="data.dangerStatus"
				clearable
				class="w-240px!"
				:options="DANGER_DESC_OPTIONS"
				placeholder="请选择风险状态"
			/>
		</el-form-item>

		<el-form-item>
			<el-divider direction="vertical" h="32px!" m="r-22px!" />
			<el-button type="primary" :loading="isLoading" @click="search">
				<template #icon>
					<el-icon class="i-custom:search" />
				</template>
				查询
			</el-button>
			<el-button @click="reset">
				<template #icon>
					<el-icon class="i-custom:reset" />
				</template>
				重置
			</el-button>
		</el-form-item>
	</el-form>
</template>
